<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>蒋路的药品详情页面</title>
</head>
<body>
	<script type="text/javascript"> 
	
	function show_search_pill_SelectedDate(rowData) { 
		var pdidyn=$("#elePrint_ic").textbox("getText");
		if(pdidyn==null || pdidyn==""){
			$.messager.confirm("确认", "你还没有输入病人卡号不能开药，是否输入卡号", function (r) {  
				 if (r) {						
					   $("#pd_searchPill_idyn_win").window({'title': "输入病人卡号"});
					   $("#pd_searchPill_idyn_win").window('open');					   
				 }else{
					 $("#pharStockInfo_tab").datagrid("unselectAll");
				 }
			});
		}else{
			$.messager.confirm("确认", "是否确定开此："+rowData.pharStockMedName, function (r) {  
		        if (r) { 		       	
		        	var price=rowData.pharStockMedName;
		        	$.ajax({
		                type: "Post",
		                url: "tojl_findByPharStockMedName",
		                data: {pharStockMedName:price  },
		                success: function (data) {			                	
		                	 $("#pharStockNumwin").window('open');	                		                	
		                     addRow(data);
		                    
		                }
		            });		        					  
		            return true;  
		        } else{
		        	 $("#pharStockInfo_tab").datagrid("unselectAll");
		        } 
		    });  
		    return false;  
		}		    			
}  

	
		$(function(){	
			
			$("#pharStock-save").linkbutton({
				onClick:function(){	
					var info="开药成功";
					Queryadc()
					$.messager.alert("温馨提示",info);
					$("#electronicePrint_nember").textbox('clear');
					$("#electronicePrint_money").textbox('clear');
					$("#electronicePrint_price").textbox('clear');
					$("#electronicePrint_Resule").textbox('clear');
					$("#pharStockNumwin").window('close');
				}
			});
			
			
			$("#pd_searchPill_idyn_save").linkbutton({			
				onClick:function(){					
					var pdidnum=$("#pd_searchPill_idyn_id").textbox("getText");
					if(pdidnum==null || pdidnum==""){
						$.messager.alert("温馨提示"+"卡号异常,请确认卡号！");
					}else{			
						var rowIndex=$('#pharStockInfo_tab').datagrid('getRowIndex',$('#pharStockInfo_tab').datagrid('getSelected'));
			        	var rowData = $('#pharStockInfo_tab').datagrid('getData').rows[rowIndex];
						$("#elePrint_ic").textbox("setText",pdidnum);
						$("#pdidyn_win").window('close');
						$.messager.confirm("确认", "是否确定开此："+rowData.pharStockMedName, function (r) {  
					        if (r) { 				        	
					        	var price=rowData.pharStockMedName;
					        	$.ajax({
					                type: "Post",
					                url: "tojl_findByPharStockMedName",
					                data: {pharStockMedName:price  },
					                success: function (data) {			                	
					                	 $("#pharStockNumwin").window('open');	                		                	
					                     addRow(data);			                    
					                }
					            });	
								$("#pd_searchPill_idyn_id").textbox("setText","");
								 $("#pd_searchPill_idyn_win").window('close');
					            return true;  
					        }  else{
					        	$("#pharStockInfo_tab").datagrid("unselectAll");
					        }
					    });  
					    return false;  					
					}				
				}
			});
		
		$("#pd_searchPill_idyn_cancel").linkbutton({
			onClick:function(){
				 alert("取消");
				 $("#pd_searchPill_idyn_id").textbox("setText","");
				 $("#pdidyn_win").window('close'); 	
				 $("#pharStockInfo_tab").datagrid("unselectAll");
			}
		});
									
			$("#w-ok").linkbutton({onClick: function(){
					var rows = $("#pharStockInfo_tab").datagrid("getSelections");
					  if(rows.length>0){
							alert("rows[i].itemid:");
							var rows = $('#pharStockInfo_tab').datagrid('getSelections');
							for(var i=0; i<rows.length; i++){
									var sear_datanum=$('#elePrintPillParticulars_tab').datagrid('getData');
									var sear_totalnum=data.total-1;
									alert('index:'+sear_totalnum);
									$('#elePrintPillParticulars_tab').datagrid('insertRow',{
											index: sear_totalnum,	
											row: {
												name: '新名称',
												age: 30,
												note: '新消息'
											}
									});							
							}												
					  } else{
						  $.messager.confirm("提示", "你没有选择任何药品，是否退出", function(v){
								if(v){									   
									$('#w').window('close')										
								  }
						  });
												
					  }			
			}});
			
			$("#w-calcle").linkbutton({onClick: function(){
				$('#w').window('close')
			}});
			
			$('#casesearch').searchbox({
			    searcher:function(value,name){
			    	$('#casetab').datagrid('loadData',{total:0,rows:[]});
			    	if(name=="卡号"){
			    		$("#casetab").datagrid({
				    		url:'tocasepage',
				    		queryParams: {
				    			price: value
				    		}
				    	});
			    	}else if(name=="身份证号"){
			    		$.ajax({
		                    type: "Post",
		                    url: "to_findbyid",
		                    data: {idcard:value},
		                    success: function (data) {
		                    	$("#casetab").datagrid({
						    		url:'tocasepage',
						    		queryParams: {
						    			price:data
						    		}
						    	});
		                    }
		                });
			    		
			    	}			    	
			    	
			    }
			});
		});
	</script>
		<div id="jl_search_pill_btn">
			<input id="casesearch" class="easyui-searchbox" data-options="menu:'#seePill',width:220,prompt:'请输入。。。。'">			
			<a class="easyui-linkbutton" style="margin-left:265px" id="w-ok" data-options="iconCls:'icon-ok'"  style="width:80px">确定</a>
			<a class="easyui-linkbutton" style="margin-left:8px"id="w-calcle" data-options="iconCls:'icon-cancel'" style="width:80px">取消</a>			
		</div>	
	  <table id="pharStockInfo_tab" class="easyui-datagrid"				    		 		
				data-options="
				fitColumns:true,
				height:370,											
				url:'to_PharStockByKindpage?pharStockMedKind='+${pharStockMedKind}, 
				border:true,
				pagination:true,
			    checkOnSelect:true,  
            	selectOncheck:true,	
            	sortOrder: 'asc',
   				sortName: 'pharStockMedName',
   				remoteSort:false,			
				pageSize:11,
				onClickRow :function(rowIndex,rowData){  
                 	show_search_pill_SelectedDate(rowData);  
                },  
				pageList:[11,22,33,44]
				">
				<thead>
					<tr>
						<th class="ident" data-options="field:'pharStockId',sortable:true,width:5,checkbox:true">库存编号</th>
						<th class="ident" data-options="field:'pharStockMedName',width:15,sortable:true,editor:'textbox'">药品</th>
						<th class="ident" data-options="field:'pharStockMedKind',sortable:true,width:10">类型</th>									
						<th class="ident" data-options="field:'pharStockGuige',sortable:true,width:10">规格</th>				
						<th class="ident" data-options="field:'pharStockUnit',sortable:true,width:12">单位</th>								
						<th class="ident" data-options="field:'maiMoney',sortable:true,width:10">金额</th>				
						<th class="ident" data-options="field:'pharStockMedDate',sortable:true,width:13,formatter:function(value){
						        var unixTimestamp = new Date(value);  
						        return unixTimestamp.toLocaleDateString();}">生产日期
						</th> 
						<th class="ident" data-options="field:'pharStockBaozhiqi',sortable:true,width:13,formatter:function(value){
						        var unixTimestamp = new Date(value);  
						        return unixTimestamp.toLocaleDateString();}">保质日期
						</th> 
					</tr>
				</thead>
	 </table>	
	<div id="seePill" style=" width:90px">
		<div date-options="name:'name'">药品名</div>
		<div date-options="name:'name'">规格</div>
	</div>	
	<div id="pd_searchPill_idyn_win" class="easyui-window"style="padding: 10px;line-height: 150%;"data-options="
		     		width: 400,
		     		height: 150,
		     		closed: true
			">			
					<div class="item" >
						<input id="pd_searchPill_idyn_id" name="pdidyn_id" class="easyui-textbox"
							data-options="label: '卡号:', width: 200">
					</div>														
					<div>
						<a id="pd_searchPill_idyn_save" class="easyui-linkbutton">确定</a>
						 <a id="pd_searchPill_idyn_cancel" class="easyui-linkbutton">取消</a>
					</div>		
		</div>
		
		<div id="pharStockNumwin" class="easyui-window"
			style="padding: 10px;line-height: 150%;"
			data-options="
		     width: 450,
		     height:204,
		     closed: true,
		     title:'开药操作'
			">		
					<table>
						<tr>
							<td>
								<div class="item">
									<input id="electronicePrint_nember"   class="easyui-textbox" data-options="label: '数量:', width: 190,validType: ['inputnum'],labelWidth:45">
								</div>
							</td>
							<td>
								<div class="item">
									<input id="electronicePrint_money"   class="easyui-textbox" data-options="label: '金额:', width: 190,labelWidth:45">
								</div>
							</td>								
						</tr>
						<tr>
							<td>
								<div class="item">
									<input id="electronicePrint_price"   class="easyui-textbox" data-options="label: '单价:', width: 190,labelWidth:45">
								</div>
							</td>
							<td>
								<div class="item">
									<input id="electronicePrint_Resule"   class="easyui-textbox" data-options="label: '备注:', width: 190,labelWidth:45">
								</div>
							</td>
							
						</tr>						
						<tr>
							<td>
								<div class="item">
									<a id="pharStock-save" class="easyui-linkbutton">确定</a>
								</div>
							</td>
							<td>
								<div class="item">
									<a id="pharStock-cancel" class="easyui-linkbutton">取消</a>
								</div>
							</td>
						</tr>
					</table>			
		</div>
</body>
</html>